﻿#include "mytcpsocket.h"

myTcpSocket::myTcpSocket(QObject *parent)
    : QTcpSocket{parent}
{
    index = -1;
}

int myTcpSocket::getIndex()
{
    return this->index;
}

void myTcpSocket::onNewDescript(qintptr socketDescriptor, int index)
{
    //发送套接字创建成功信号
    this->setSocketDescriptor(socketDescriptor);
    this->index = index;
    if(this->isOpen()){
        emit socketReady(this->index);

    }
}

void myTcpSocket::onCloseSocket(int index)
{

    //释放套接字资源
    if(index == this->index){
        this->disconnectFromHost();
        this->close();
        this->deleteLater();
    }
}

void myTcpSocket::onSendByteArray(QByteArray array,int index)
{
    //发送数据
    if(index == this->index){
        this->write(array);
    }
}




